<template>
	<view>
		<uni-nav-bar @clickLeft="goback" left-icon="back" fixed title="评价管理" status-bar="true"></uni-nav-bar>
		<view class="" v-if="info.replyCount!=0">
			<view class="top">
				<view class="" style="margin-top: 15rpx;">
					全部({{info.replyCount?info.replyCount:0}})
				</view>
				<view class="textrig">
					<view class="">{{info.rating?info.rating:0}}</view>
					<uni-rate class="x" readonly="true" value="4" size='16' activeColor="#000"></uni-rate>
				</view>
			</view>
			<view class="block_1">
				<view class="tipflex">
					<view class="ites" :class="item.isclick?'itesact':'ites'" v-for="(item,index) in vuetaglist"
						:key="index" @click="changeTag(item)">
						{{item.title}} ({{item.value}})
					</view>
				</view>
				<view class="change">
					<label @click="changeImg()"
					 class="radio" style="display: flex;align-items: center;">
						<radio :checked="isfalse" color="#000000" style="transform: scale(0.7);" />
						<text :style="{color:isfalse?'#000000':''}">只看有图</text>
					</label>
				</view>
			</view>
			<view class="plist">
				<view class="items" v-for="(item,index) in vuecommentList" :key="index" @click="pagePer(item)">
					<view class="items_user">
						<view class="user_flex">
							<image class="uimg" :src="item.userHead?item.userHead:'/static/toux.png'" mode="aspectFit"></image>
							<view class="uname">
								{{item.userName}}
							</view>
						</view>
						<view class="time">{{item.createTime}}</view>
					</view>
					<view class="star">
						<uni-rate readonly="true" :value="item.rating" size='19' activeColor="#000"></uni-rate>
					</view>
					<view class="text">{{item.content}}</view>
					<view class="pimglist" v-if="item.img">
						<image @click.stop="preview(item.img,ind)" v-for="(img,ind) in item.img" :key="ind" :src="img"
							mode="scaleToFill"></image>
					</view>
					<view class="shop">
						{{item.productName}}({{item.productCount}}份)
						<span>￥{{item.productPrice}}</span><span class="s2">￥{{item.productPriceOld}}</span>
					</view>
					<view class="imgflex">
						<view class="tipflexs">
							<view class="ites" v-for="(tag,ind) in item.tag" :key="ind">
								{{tag}}
							</view>
						</view>
						<view class="img_r">
							<view class="r">
								<span>{{item.replyCount}}</span>
								<uni-icons size="20" color='#D9D9D9' type="chat"></uni-icons>
							</view>
						</view>
					</view>
					<view class="dialog" v-if="item.replyList!=0">
						<view class="itemss" v-for="(reply,index) in item.replyList" :key="index">
							<view class="items_users">
								<view class="items_conts">
									<view class="user_flexs">
										<image class="uimg" :src="reply.sendUserHead?reply.sendUserHead:'/static/toux.png'" mode=""></image>
										
										<view class="uname">{{reply.sendUserName}}</view>
										<view class="tipss" v-if="reply.sendUserShop == 1">
											店铺
										</view>
										<view class="tipss1" v-if="reply.sendUserShop == 2">
											平台
										</view>
									</view>
									<view class="cont" v-if="reply.reply==1">
										<view class="hf">
											回复
										</view>
										<span>{{reply.receiveUserName}}</span>
									</view>
								</view>
								<view class="time">{{reply.createTime}}</view>
							</view>
							<view class="contxt">
								{{reply.content}}
							</view>
						</view>
					</view>
				</view>
			</view>
			<view class="kong" v-if="nolist">
				<image src="/static/kpj.png" mode=""></image>
				<view class="">
					尚无评价
				</view>
			</view>
		</view>
		<view class="kong" v-else>
			<image src="/static/kpj.png" mode=""></image>
			<view class="">
				尚无评价
			</view>
		</view>
	</view>
</template>

<script>
	import {
		tagList,
		commentList
	} from '@/common/http.api.js';
	export default {
		data() {
			return {
				isfalse: false,
				vuetaglist: [],
				
				params:{
					pageNum: 1,
					pageSize: 10,
					tag:'',
					img:'',
				},
				vuecommentList: [],
				nolist:false,
				info:{}
			};
		},
		onLoad() {
			this.info = uni.getStorageSync('userinfo')
			tagList({}).then(res => {
				let list = Object.keys(res.data)
				this.vuetaglist = list.map(item => {
					return {
						title: item,
						value: res.data[item],
						isclick: false
					}
				})
			})
			commentList(this.params).then(res => {
				res.rows.forEach(item => {
					item.img = item.img?.split(',')
					item.tag = item.tag?.split(',')
				})
				this.vuecommentList = res.rows
				let total = Math.ceil(res.total / this.params.pageSize);
				this.nolist = total == 0
			})
		},
		onReachBottom() {
			this.params.pageNum++
			commentList(this.params).then(res => {
				res.rows.forEach(item => {
					item.img = item.img?.split(',')
					item.tag = item.tag?.split(',')
				})
				this.vuecommentList.push(...res.rows)
				let total = Math.ceil(res.total / this.params.pageSize);
				this.nolist = total == 0
				if(this.vuecommentList.length == res.total){
					uni.showToast({
						title:'已加载全部',
						icon:'none'
					})
				}
			})
			
		},
		methods: {
			changeImg(){
				this.isfalse = !this.isfalse
				this.params.pageNum = 1
				this.params.img = this.isfalse?1:0
				commentList(this.params).then(res => {
					res.rows.forEach(item => {
						item.img = item.img?.split(',')
						item.tag = item.tag?.split(',')
					})
					this.vuecommentList = res.rows
					let total = Math.ceil(res.total / this.params.pageSize);
					this.nolist = total == 0
				})
			},
			changeTag(item){
				item.isclick = !item.isclick
				this.params.pageNum = 1
				let list = this.vuetaglist.filter((item=>{
					return item.isclick
				})).map(i=>{return i.title})
				this.params.tag = list.join(',')
				commentList(this.params).then(res => {
					res.rows.forEach(item => {
						item.img = item.img?.split(',')
						item.tag = item.tag?.split(',')
					})
					this.vuecommentList = res.rows
					let total = Math.ceil(res.total / this.params.pageSize);
					this.nolist = total == 0
				})
			},
			preview(list,index) {
				uni.previewImage({
					current:index,
					urls: list,
				});
			},
			//跳转某一条评论
			pagePer(item) {
				console.log(item);
				uni.navigateTo({
					url: `/pages/user/perComment?id=${item.id}`
				})
			},
			goback() {
				uni.navigateBack()
			},
		}
	}
</script>

<style lang="scss">
	.kong {
		margin: 150rpx auto;
		text-align: center;
		font-family: PingFang SC, PingFang SC;
		font-weight: bold;
		font-size: 36rpx;
		color: #000000;
	
		image {
			width: 228rpx;
			height: 228rpx;
		}
	}
	.top {
		border-bottom: 1px solid #eee;
		width: 750rpx;
		height: 120rpx;
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 20rpx;
		box-sizing: border-box;
		font-family: PingFang SC, PingFang SC;
		font-weight: bold;
		font-size: 30rpx;
		color: #000000;

		.textrig {
			display: flex;
			font-family: 'DINB';
			font-size: 48rpx;

			.x {
				margin-top: 20rpx;
			}
		}
	}

	.block_1 {
		padding: 20rpx;
		box-sizing: border-box;

		.tipflex {
			display: flex;
			flex-wrap: wrap;

			.ites {
				height: 48rpx;
				background: #F9F9F9;
				border-radius: 0rpx 0rpx 0rpx 0rpx;
				padding: 0rpx 14rpx;
				text-align: center;
				line-height: 48rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 26rpx;
				color: #B4B4B4;
				margin: 0rpx 10rpx 20rpx 0rpx;
			}

			.itesact {
				background: #036029;
				color: #FFFFFF;
			}
		}

		.change {
			display: flex;
			justify-content: space-between;
			align-items: center;
			font-family: PingFang SC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #D1CDCD;
		}
	}

	.plist {
		font-family: PingFang SC, PingFang SC;
		padding: 0rpx 20rpx 40rpx 20rpx;
		box-sizing: border-box;
		.items {
			border-top: 1px solid #eee;
			;
			padding: 30rpx 0rpx;

			.items_user {
				display: flex;
				align-items: center;
				justify-content: space-between;

				.user_flex {
					display: flex;
					align-items: center;

					.uimg {
						width: 50rpx;
						height: 50rpx;
						border-radius: 25rpx;
					}

					.uname {
						font-weight: bold;
						font-size: 32rpx;
						color: #000000;
						margin-left: 10rpx;
					}
				}

				.time {
					font-size: 24rpx;
					color: #979797;
				}
			}

			.star {
				margin: 14rpx auto;
			}

			.text {
				font-weight: 500;
				font-size: 28rpx;
				color: #000000;
			}

			.pimglist {
				display: flex;
				justify-content: space-between;
				margin-top: 20rpx;

				image {
					width: 230rpx;
					height: 210rpx;
				}
			}

			.shop {
				height: 68rpx;
				background: #F3F3F3;
				border-radius: 0rpx 0rpx 0rpx 0rpx;
				font-family: PingFang SC, PingFang SC;
				font-weight: 500;
				font-size: 24rpx;
				color: #000000;
				padding: 0rpx 20rpx;
				line-height: 68rpx;
				box-sizing: border-box;
				display: inline-block;
				margin: 20rpx auto 0rpx;

				span {
					font-family: 'DINB';
				}

				.s2 {
					color: #D1CDCD;
					font-size: 22rpx;
					text-decoration-line: line-through;
					margin-left: 6rpx;
				}
			}

			.imgflex {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin: 20rpx auto;

				.tipflexs {
					flex: 1;
					display: flex;

					.ites {
						height: 48rpx;
						background: #036029;
						border-radius: 0rpx 0rpx 0rpx 0rpx;
						padding: 0rpx 14rpx;
						text-align: center;
						line-height: 48rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						font-size: 24rpx;
						color: #FFFFFF;
						margin-right: 10rpx;
					}
				}

				.img_r {
					display: flex;
					align-items: center;

					.r {
						display: flex;
						margin-left: 20rpx;
						align-items: center;
					}

					span {
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						font-size: 28rpx;
						color: #D1CDCD;
					}
				}
			}

			.dialog {
				background: #FAF9F7;
				border-radius: 0rpx 0rpx 0rpx 0rpx;
				padding: 22rpx 24rpx;

				.itemss {
					margin-bottom: 24rpx;

					.items_users {
						display: flex;
						align-items: center;
						justify-content: space-between;

						.items_conts {
							display: flex;
							align-items: center;

							.cont {
								display: flex;
								align-items: center;
								font-family: PingFang SC, PingFang SC;
								font-weight: 500;
								font-size: 28rpx;
								color: #000000;

								.hf {
									color: #CE7034;
									margin: 0 10rpx;
								}
							}
						}

						.user_flexs {
							display: flex;
							align-items: center;

							.uimg {
								width: 40rpx;
								height: 40rpx;
								border-radius: 25rpx;
							}

							.uname {
								font-size: 28rpx;
								color: #000000;
								margin-left: 10rpx;
							}
							.tipss{
								width: 80rpx;
								background: #000000;
								border-radius: 0rpx 0rpx 0rpx 0rpx;
								font-family: PingFang SC, PingFang SC;
								font-weight: 500;
								font-size: 24rpx;
								color: #FFFFFF;
								line-height: 36rpx;
								text-align: center;
								margin-left: 10rpx;
							}
							.tipss1{
								width: 80rpx;
								background: #036029;
								border-radius: 0rpx 0rpx 0rpx 0rpx;
								font-family: PingFang SC, PingFang SC;
								font-weight: 500;
								font-size: 24rpx;
								line-height: 36rpx;
								color: #FFFFFF;
								text-align: center;
								margin-left: 10rpx;
							}
						}

						.time {
							font-size: 24rpx;
							color: #979797;
						}
					}

					.contxt {
						margin-top: 20rpx;
						font-family: PingFang SC, PingFang SC;
						font-weight: 500;
						font-size: 24rpx;
						color: #666666;
					}
				}

				.items:last-child {
					margin-bottom: 0rpx;
				}

			}
		}
	}
</style>